<?php if ( ! defined('BASEPATH')) exit('This file does not run directly. Sorry.'); ?>
<?php
/**
 * Kalaisoo.
 *
 * A lightweight no-framework framework written in PHP.
 *
 * @package Kalaisoo
 * @author $Author: info@sah-company.com $
 * @version $Id: media.php 130 2012-01-14 13:29:27Z info@sah-company.com $
 */

/**
 * Kalaisoo Media Model Class.
 *
 * @package Kalaisoo
 * @subpackage Model
 * @author $Author: info@sah-company.com $
 */
class Model_Media extends Model
{
	/**
	 * __construct.
	 */
	public function construct()
	{
		parent::__construct();
	}
	
	/**
	 * returns the tags of a bean.
	 *
	 * @return array
	 */
	public function getTags() {
		return array(
			$this->bean->name,
			$this->bean->description,
			$this->bean->author
		);
	}
	
	/**
	 * loads the array $this->gestalt of this bean for use with Model::gestalt().
	 */
	public function loadGestalten()
	{
		$this->gestalt['default'] = array(
			array(
				'type' => 'file',
				'name' => 'file_name',
				'help' => __('media_file_name_help'),
				'parameters' => array(
				)
			),
			array(
				'type' => 'text',
				'name' => 'name',
				'help' => __('media_name_help'),
				'parameters' => array(
					'placeholder' => __('media_name_placeholder'),
				)
			),
			array(
				'type' => 'textarea',
				'name' => 'description',
				'help' => __('media_description_help'),
				'parameters' => array(
					'placeholder' => __('media_description_placeholder'),
				)
			),
			array(
				'type' => 'text',
				'name' => 'author',
				'help' => __('media_author_help'),
				'parameters' => array(
					'placeholder' => __('media_author_placeholder'),
				)
			)
		);
	}
	
	/**
	 * validates the data and returns either true or false.
	 *
	 * @return bool
	 */
	public function validate()
	{
		$valid = true;
		return $valid;
	}

	/**
	 * open.
	 */
	public function open()
	{
	}

	/**
	 * dispense.
	 */
	public function dispense()
	{
	}

	/**
	 * update.
	 */
	public function update()
	{
		if ($file = Filesystem::moveUploadedFile('uploaded_file')) {
			$this->bean->file_name = $file;
			if ( ! $this->bean->name) $this->bean->name = $file;
		}
	}
	
	/**
	 * after_update.
	 */
	public function after_update()
	{
	}
	
	/**
	 * delete.
	 */
	public function delete()
	{
		Filesystem::unlink(Registry::instance()->config['uploads']['folder'].'/'.$this->bean->file_name);
	}
	
	/**
	 * after_delete.
	 */
	public function after_delete()
	{
	}
}
?>